package com.woniu.project.dao;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniu.project.core.domain.ProductEntity;
import com.woniu.project.dto.productentitydto.ProductEntityDto;
import com.woniu.project.dto.productentitydto.ProductEntityListDto;
import com.woniu.project.dto.productentitydto.ProductEntityOneDto;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author WHF
 * @since 2020-10-13
 */
public interface ProductEntityMapper extends BaseMapper<ProductEntity> {

    IPage<ProductEntityListDto> selectProductEntityList(Page<ProductEntityListDto> page, @Param("productEntityStatus") String productEntityStatus, @Param("operator") String operator, @Param("productParams") String productParams, @Param("startTime") Date startTime, @Param("endTime") Date endTime);

    @Select("SELECT pe.* from pawn_product_small_type s\n" +
            "right JOIN pawn_product p on \n" +
            "p.product_small_type_id=s.product_small_type_id\n" +
            "right JOIN pawn_product_entity pe on pe.product_id=p.product_id\n" +
            "where s.product_small_type_id=#{smallTypeId}")
    List<ProductEntityDto> selectBySmallTypeId(Integer smallTypeId);

    @Select("SELECT pe.* from pawn_product_small_type s\n" +
            "JOIN pawn_product p on \n" +
            "p.product_small_type_id=s.product_small_type_id\n" +
            "JOIN pawn_product_entity pe on pe.product_id=p.product_id\n" +
            "JOIN pawn_product_big_type b on\n" +
            " s.product_big_type_id=b.product_big_type_id\n" +
            "where b.product_big_type_id=#{bigTypeId}")
    List<ProductEntityDto> selectByBigTypeId(Integer bigTypeId);

    @Select("select * from pawn_product_entity where product_brand_id=#{brandId}")
    List<ProductEntityDto> selectByBrandId(Integer brandId);

    @Select("SELECT pe.* from pawn_product_entity pe\n" +
            "LEFT JOIN pawn_product p on \n" +
            "p.product_id=pe.product_id\n" +
            "LEFT JOIN pawn_product_property_centre pc on \n" +
            "pc.product_id=p.product_id\n" +
            "where pc.product_property_id=#{propertyId}")
    List<ProductEntityDto> selectByPropertyId(Integer propertyId);

    @Select("SELECT pe.product_entity_id,sh.shop_name,\n" +
            "m.management_name enter_man_name,\n" +
            "pe.product_entity_enter_time,\n" +
            "p.product_name,s.product_small_type_name,b.product_big_type_name,\n" +
            "pe.product_entity_name,br.product_brand_name,commodity_number,\n" +
            "pe.product_entity_original_price,product_entity_desc\n" +
            "from pawn_product_entity pe LEFT JOIN\n" +
            "pawn_shop sh on pe.shop_id=sh.shop_id LEFT JOIN \n" +
            "pawn_management m on pe.enter_man_id=m.management_id LEFT JOIN\n" +
            "pawn_product p on pe.product_id=p.product_id \n" +
            "LEFT JOIN pawn_product_small_type s \n" +
            "on p.product_small_type_id=s.product_small_type_id \n" +
            "LEFT JOIN pawn_product_big_type b \n" +
            "on b.product_big_type_id=s.product_big_type_id LEFT JOIN\n" +
            "pawn_product_brand br on pe.product_brand_id=br.product_brand_id\n" +
            "where pe.product_entity_id=#{productEntityId}")
    ProductEntityOneDto selectOneProductEntity(Integer productEntityId);
}
